home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / hplip / ui4 / deviceuricombobox.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-10-28  |  4KB  |  126 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from base.g import *
  5. from ui_utils import *
  6. from base import device
  7. from PyQt4.QtCore import *
  8. from PyQt4.QtGui import *
  9. DEVICEURICOMBOBOX_TYPE_PRINTER_ONLY = 0
  10. DEVICEURICOMBOBOX_TYPE_FAX_ONLY = 1
  11. DEVICEURICOMBOBOX_TYPE_PRINTER_AND_FAX = 2
  12.  
  13. class DeviceUriComboBox(QWidget):
  14.     
  15.     def __init__(self, parent):
  16.         QWidget.__init__(self, parent)
  17.         self.device_uri = ''
  18.         self.initial_device = None
  19.         self.updating = False
  20.         self.typ = DEVICEURICOMBOBOX_TYPE_PRINTER_ONLY
  21.         self.filter = None
  22.         self.devices = None
  23.         self.user_settings = UserSettings()
  24.         self.user_settings.load()
  25.         self.user_settings.debug()
  26.         self.initUi()
  27.  
  28.     
  29.     def initUi(self):
  30.         HBoxLayout = QHBoxLayout(self)
  31.         HBoxLayout.setObjectName('HBoxLayout')
  32.         self.NameLabel = QLabel(self)
  33.         self.NameLabel.setObjectName('NameLabel')
  34.         HBoxLayout.addWidget(self.NameLabel)
  35.         SpacerItem = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Minimum)
  36.         HBoxLayout.addItem(SpacerItem)
  37.         self.ComboBox = QComboBox(self)
  38.         sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
  39.         sizePolicy.setHorizontalStretch(0)
  40.         sizePolicy.setVerticalStretch(0)
  41.         sizePolicy.setHeightForWidth(self.ComboBox.sizePolicy().hasHeightForWidth())
  42.         self.ComboBox.setSizePolicy(sizePolicy)
  43.         self.ComboBox.setObjectName('ComboBox')
  44.         HBoxLayout.addWidget(self.ComboBox)
  45.         self.NameLabel.setText(self._DeviceUriComboBox__tr('Device:'))
  46.         self.connect(self.ComboBox, SIGNAL('currentIndexChanged(const QString &)'), self.ComboBox_currentIndexChanged)
  47.  
  48.     
  49.     def setType(self, typ):
  50.         if typ in (DEVICEURICOMBOBOX_TYPE_PRINTER_ONLY, DEVICEURICOMBOBOX_TYPE_FAX_ONLY, DEVICEURICOMBOBOX_TYPE_PRINTER_AND_FAX):
  51.             self.typ = typ
  52.         
  53.  
  54.     
  55.     def setFilter(self, filter):
  56.         self.filter = filter
  57.  
  58.     
  59.     def setInitialDevice(self, device_uri):
  60.         self.initial_device = device_uri
  61.  
  62.     
  63.     def setDevices(self):
  64.         if self.typ == DEVICEURICOMBOBOX_TYPE_PRINTER_ONLY:
  65.             be_filter = [
  66.                 'hp']
  67.         elif self.typ == DEVICEURICOMBOBOX_TYPE_FAX_ONLY:
  68.             be_filter = [
  69.                 'hpfax']
  70.             self.NameLabel.setText(self._DeviceUriComboBox__tr('Fax Device:'))
  71.         else:
  72.             be_filter = [
  73.                 'hp',
  74.                 'hpfax']
  75.         self.devices = device.getSupportedCUPSDevices(be_filter, self.filter)
  76.         return len(self.devices)
  77.  
  78.     
  79.     def updateUi(self):
  80.         if self.devices is None:
  81.             self.setDevices()
  82.         
  83.         self.device_index = { }
  84.         if self.devices:
  85.             if self.initial_device is None:
  86.                 self.initial_device = self.user_settings.last_used_device_uri
  87.             
  88.             self.updating = True
  89.             
  90.             try:
  91.                 k = 0
  92.                 for i, d in enumerate(self.devices):
  93.                     self.ComboBox.insertItem(i, d)
  94.                     if self.initial_device is not None and d == self.initial_device:
  95.                         self.initial_device = None
  96.                         k = i
  97.                         continue
  98.                 
  99.                 self.ComboBox.setCurrentIndex(-1)
  100.             finally:
  101.                 self.updating = False
  102.  
  103.             self.ComboBox.setCurrentIndex(k)
  104.             if len(self.devices) == 1:
  105.                 self.emit(SIGNAL('DeviceUriComboBox_oneDevice'))
  106.             
  107.         else:
  108.             self.emit(SIGNAL('DeviceUriComboBox_noDevices'))
  109.  
  110.     
  111.     def ComboBox_currentIndexChanged(self, t):
  112.         if self.updating:
  113.             return None
  114.         self.device_uri = unicode(t)
  115.         if self.device_uri:
  116.             self.user_settings.last_used_device_uri = self.device_uri
  117.             self.user_settings.save()
  118.             self.emit(SIGNAL('DeviceUriComboBox_currentChanged'), self.device_uri)
  119.         
  120.  
  121.     
  122.     def __tr(self, s, c = None):
  123.         return qApp.translate('DeviceUriComboBox', s, c)
  124.  
  125.  
  126.